# 1导包
import unittest
import jsonschema
from api.Ihrm_login_api import IhrmLoginApi


class TestIhrmLogin(unittest.TestCase):
    # 登录成功
    def test01_login_ok(self):
        data = {"mobile": "13800000002", "password": "123456"}
        res = IhrmLoginApi.IhrmLogin(data)
        print("响应结果", res.json())
        # 断言
        # assert_ulit(self, res, 200, True, 10000, '操作成功！')
        #         使用全量字段校验 替换断言

        # 断言 校验响应状态码
        self.assertEqual(200, res.status_code)

        # 检验规格
        schema = {
            "type": "object",
            "properties": {
                "success": {
                    "const": True
                },
                "code": {
                    "const": 10000
                },
                "message": {
                    "pattern": "操作成功"
                },
                "data": {
                    "type": "string"
                }
            },
            "required": ["success", "code", "message", "data"]
        }
        # 调用jsonschema校验函数
        jsonschema.validate(instance=res.json(), schema=schema)